module.exports = function ($scope, $resource, $modal, toaster) {

	//查询法规列表
	$scope.search = function(pageNo) {
		var para = {
			'pageNo': pageNo,
			'pageSize': $scope.itemsPerPage,
			'company_code': $scope.searchform.code,
			'issue_status': $scope.searchform.issue_status
		}
		$resource('/api/ac/atc/auditReportService/getIssueList', {}, {}).save(para, function(res){
            if (res.errcode === 0) {
				$scope.issueList = res.data.results;
				$scope.totalItems = res.data.totalRecord;
				$scope.currentPage = pageNo;
            } else {
                toaster.error({title: '', body: '查询信息失败'});
            }
        });
	}

	//加载参加招徕奖励活动的机构名单
	$scope.loadCompany = function() {
		$resource('/api/as/atc/tourist/companySimList', {}, {}).save({}, function(res){
            if (res.errcode === 0) {
				$scope.searchform.company_list = res.data;
            } else {
                toaster.error({title: '', body: res.errmsg});
            }
        });
	}

	init();
	function init() {
		$scope.currentPage = 1;			//当前页码
		$scope.itemsPerPage = 10;		//每页显示几条
		$scope.searchform = {
			'issue_status': '',
			'status': [
				{'name': '全部', 'code': ''},
				{'name': '已发放', 'code': '1'},
				{'name': '未发放', 'code': '0'}
			]
		};
		$scope.search(1);
		$scope.loadCompany();
	}

	//详情&确认发放
	$scope.getInfo = function(info, flag) {
		var modalInstance = $modal.open({
			template: require('../views/confirmIssue.html'),
			controller: 'confirmIssue',
			size: 'lg',
			resolve: {
				item: function () {
					return info;
				},
				flag: function () {
					return flag;
				}
			}
		});
		//关闭模态框刷新页面
		modalInstance.result.then(function(result) {
			$scope.search($scope.currentPage);
		});
	}


};